<template>
  <div class="app-container">
    <!-- 客户列表区域 -->
    <el-card class="app-card" :body-style="{ padding: '24px' }">
      <div class="search-bar">
        <el-input
          v-model="queryParams.customer_name"
          placeholder="请输入客户名称"
          class="search-input"
          clearable
          @keyup.enter="handleQuery"
        />
        <el-button type="primary" class="search-button" @click="handleQuery">搜索</el-button>
        <el-button class="reset-button" @click="resetQuery">重置</el-button>
      </div>
      
      <div class="table-header">
        <div class="left-buttons">
          <el-button type="primary" class="action-button add-button" @click="handleAdd">
            <el-icon class="button-icon"><plus /></el-icon>添加
          </el-button>
          <el-button type="danger" class="action-button" :disabled="selectedCustomers.length === 0" @click="handleBatchDelete">
            <el-icon class="button-icon"><delete /></el-icon>批量删除
          </el-button>
        </div>
        <div class="right-buttons">
          <el-button type="success" class="action-button export-button" @click="handleExport">
            <el-icon class="button-icon"><download /></el-icon>导出
          </el-button>
          <el-button type="primary" class="action-button import-button" @click="handleImport">
            <el-icon class="button-icon"><upload /></el-icon>导入
          </el-button>
        </div>
      </div>
      
      <el-table
        v-loading="loading"
        :data="customerList"
        border
        style="width: 100%"
        @selection-change="handleSelectionChange"
        class="data-table"
      >
        <el-table-column type="selection" width="55" />
        <el-table-column type="index" label="#" width="60" align="center" />
        <el-table-column label="操作" width="180" fixed="left">
          <template #default="scope">
            <el-button type="primary" link class="table-button" @click="handleEdit(scope.row)">编辑</el-button>
            <el-button type="danger" link class="table-button" @click="handleDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="id" label="ID" width="80" sortable />
        <el-table-column prop="customer_name" label="客户名称" width="180" />
        <el-table-column prop="customer_source_display" label="客户来源" width="150">
          <template #default="scope">
            <el-tag class="source-tag">{{ getCustomerSourceLabel(scope.row.customer_source) }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="phone_number" label="手机号码" width="150" />
        <el-table-column label="订单明细记录" min-width="200">
          <template #default="scope">
            <div class="order-links">
              <el-link 
                v-for="order in scope.row.orders" 
                :key="order.id" 
                type="primary" 
                @click="handleViewOrder(order.id)"
                class="order-link"
              >
              {{ order.id }}
              </el-link>
              <span v-if="!scope.row.orders || scope.row.orders.length === 0" class="no-data">暂无订单</span>
            </div>
          </template>
        </el-table-column>
      </el-table>
      
      <div class="table-pagination">
        <el-pagination
          v-model:current-page="pagination.page"
          v-model:page-size="pagination.pageSize"
          :page-sizes="[10, 20, 50, 100]"
          :total="pagination.total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          background
          class="pagination"
        />
      </div>
    </el-card>

    <!-- 添加/编辑客户弹窗 -->
    <el-dialog
      :title="dialogTitle"
      v-model="dialogVisible"
      width="500px"
      append-to-body
      destroy-on-close
      class="custom-dialog"
    >
      <el-form
        ref="customerFormRef"
        :model="customerForm"
        :rules="rules"
        label-width="100px"
        class="dialog-form"
      >
        <el-form-item label="客户名称" prop="customer_name">
          <el-input v-model="customerForm.customer_name" placeholder="请输入客户名称" class="form-input" />
        </el-form-item>
        <el-form-item label="客户来源" prop="customer_source">
          <el-select v-model="customerForm.customer_source" placeholder="请选择客户来源" class="form-input">
            <el-option :value="0" label="Newbe工作室" />
            <el-option :value="1" label="纽币德信息科技" />
            <el-option :value="2" label="官方网站" />
            <el-option :value="3" label="其它" />
          </el-select>
        </el-form-item>
        <el-form-item label="手机号码" prop="phone_number">
          <el-input v-model="customerForm.phone_number" placeholder="请输入手机号码" class="form-input" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button class="cancel-button" @click="dialogVisible = false">取消</el-button>
          <el-button type="primary" class="submit-button" @click="submitForm">提交</el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 查看订单详情弹窗 -->
    <el-dialog
      title="订单详情"
      v-model="orderDialogVisible"
      width="650px"
      append-to-body
      destroy-on-close
      class="custom-dialog"
    >
      <div v-loading="orderLoading">
        <div v-if="orderDetail" class="order-detail">
          <el-descriptions :column="2" border>
            <el-descriptions-item label="订单号">{{ orderDetail.order_number }}</el-descriptions-item>
            <el-descriptions-item label="客户名称">{{ orderDetail.customer_name_display }}</el-descriptions-item>
            <el-descriptions-item label="产品名称">{{ orderDetail.product_name_display }}</el-descriptions-item>
            <el-descriptions-item label="订单金额">{{ orderDetail.order_amount }}</el-descriptions-item>
            <el-descriptions-item label="购买年限">{{ orderDetail.purchase_years_display }}</el-descriptions-item>
            <el-descriptions-item label="订单状态">{{ orderDetail.order_status_display }}</el-descriptions-item>
            <el-descriptions-item label="授权域名">{{ orderDetail.authorized_domain }}</el-descriptions-item>
            <el-descriptions-item label="激活日期">{{ orderDetail.activation_date || '未激活' }}</el-descriptions-item>
            <el-descriptions-item label="激活人">{{ orderDetail.nickname_display || '无' }}</el-descriptions-item>
            <el-descriptions-item label="订单备注" :span="2">{{ orderDetail.order_remarks || '无' }}</el-descriptions-item>
          </el-descriptions>
        </div>
      </div>
    </el-dialog>

    <!-- 客户导入对话框 -->
    <el-dialog
      title="导入客户数据"
      v-model="importDialogVisible"
      width="500px"
      destroy-on-close
      class="custom-dialog"
    >
      <div class="import-container">
        <div class="import-tips">
          <p>温馨提示：</p>
          <ol>
            <li>请先下载导入模板，按照模板格式填写数据后上传</li>
            <li>支持Excel格式文件(.xlsx, .xls)</li>
            <li>数据量较大时请耐心等待</li>
          </ol>
        </div>
        
        <div class="template-download">
          <el-button type="primary" link class="download-button" @click="downloadTemplate">
            <el-icon class="button-icon"><download /></el-icon>下载导入模板
          </el-button>
        </div>
        
        <el-upload
          ref="uploadRef"
          class="upload-demo"
          drag
          action="#"
          :auto-upload="false"
          :on-change="handleFileChange"
          :on-drop="handleDrop"
          :on-exceed="handleExceed"
          :limit="1"
          :accept="'.xlsx,.xls'"
        >
          <el-icon class="el-icon--upload"><upload-filled /></el-icon>
          <div class="el-upload__text">
            将文件拖到此处，或<em>点击上传</em>
          </div>
          <template #tip>
            <div class="el-upload__tip">
              只能上传Excel文件(.xlsx, .xls)，且客户名称不能重复
            </div>
          </template>
        </el-upload>
      </div>
      
      <template #footer>
        <div class="dialog-footer">
          <el-button class="cancel-button" @click="importDialogVisible = false">取消</el-button>
          <el-button type="primary" class="submit-button" @click="submitImport" :loading="importLoading">
            开始导入
          </el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted } from 'vue';
import { ElMessage, ElMessageBox } from 'element-plus';
import { getCustomerList, getCustomer, createCustomer, updateCustomer, deleteCustomer, exportCustomers, importCustomers, getImportTemplate } from '@/api/customers';
import { getOrder } from '@/api/orders';
import { UploadFilled, Download, Upload, Plus, Delete } from '@element-plus/icons-vue';

// 查询参数
const queryParams = reactive({
  customer_name: '',
  page: 1,
  page_size: 10
});

// 表格数据
const customerList = ref([]);
const loading = ref(false);
const selectedCustomers = ref([]);

// 分页信息
const pagination = reactive({
  page: 1,
  pageSize: 10,
  total: 0
});

// 表单相关
const dialogVisible = ref(false);
const dialogTitle = ref('添加客户');
const customerForm = reactive({
  customer_name: '',
  customer_source: 0,
  phone_number: ''
});

// 订单详情相关
const orderDialogVisible = ref(false);
const orderDetail = ref(null);
const orderLoading = ref(false);

// 表单规则
const rules = {
  customer_name: [{ required: true, message: '请输入客户名称', trigger: 'blur' }],
  customer_source: [{ required: true, message: '请选择客户来源', trigger: 'change' }]
};

const customerFormRef = ref(null);

// 导入相关
const importDialogVisible = ref(false);
const importLoading = ref(false);
const uploadRef = ref(null);
const importFile = ref(null);

// 初始化
onMounted(() => {
  getList();
});

// 获取客户列表
const getList = async () => {
  loading.value = true;
  try {
    const response = await getCustomerList({
      ...queryParams,
      page: pagination.page,
      page_size: pagination.pageSize
    });
    customerList.value = response.results || [];
    pagination.total = response.count || 0;
  } catch (error) {
    console.error(error);
  } finally {
    loading.value = false;
  }
};

// 获取客户来源标签
const getCustomerSourceLabel = (source) => {
  const sourceMap = {
    0: 'Newbe工作室',
    1: '纽币德信息科技',
    2: '官方网站',
    3: '其它'
  };
  return sourceMap[source] || '未知';
};

// 处理查询
const handleQuery = () => {
  pagination.page = 1;
  getList();
};

// 重置查询
const resetQuery = () => {
  queryParams.customer_name = '';
  handleQuery();
};

// 处理添加
const handleAdd = () => {
  dialogTitle.value = '添加客户';
  customerForm.customer_name = '';
  customerForm.customer_source = 0;
  customerForm.phone_number = '';
  dialogVisible.value = true;
};

// 处理编辑
const handleEdit = async (row) => {
  dialogTitle.value = '编辑客户';
  try {
    const response = await getCustomer(row.id);
    customerForm.id = response.id;
    customerForm.customer_name = response.customer_name;
    customerForm.customer_source = response.customer_source;
    customerForm.phone_number = response.phone_number;
    dialogVisible.value = true;
  } catch (error) {
    console.error(error);
  }
};

// 处理删除
const handleDelete = (row) => {
  ElMessageBox.confirm('确认要删除该客户吗？这可能会影响关联的订单数据。', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(async () => {
    try {
      await deleteCustomer(row.id);
      ElMessage.success('删除成功');
      getList();
    } catch (error) {
      console.error(error);
    }
  }).catch(() => {});
};

// 处理查看订单
const handleViewOrder = async (orderId) => {
  orderDialogVisible.value = true;
  orderLoading.value = true;
  orderDetail.value = null;
  
  try {
    const response = await getOrder(orderId);
    orderDetail.value = response;
  } catch (error) {
    console.error(error);
  } finally {
    orderLoading.value = false;
  }
};

// 提交表单
const submitForm = async () => {
  if (!customerFormRef.value) return;
  
  await customerFormRef.value.validate(async (valid) => {
    if (valid) {
      try {
        if (customerForm.id) {
          await updateCustomer(customerForm.id, customerForm);
          ElMessage.success('更新成功');
        } else {
          await createCustomer(customerForm);
          ElMessage.success('添加成功');
        }
        dialogVisible.value = false;
        getList();
      } catch (error) {
        console.error(error);
      }
    }
  });
};

// 处理导出
const handleExport = async () => {
  try {
    const response = await exportCustomers(queryParams);
    // 创建Blob链接并下载
    const blob = new Blob([response.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
    const link = document.createElement('a');
    link.href = URL.createObjectURL(blob);
    link.download = '客户数据.xlsx';
    link.click();
    URL.revokeObjectURL(link.href);
  } catch (error) {
    console.error(error);
  }
};

// 处理分页大小变化
const handleSizeChange = (val) => {
  pagination.pageSize = val;
  getList();
};

// 处理页码变化
const handleCurrentChange = (val) => {
  pagination.page = val;
  getList();
};

// 处理选中行变化
const handleSelectionChange = (selection) => {
  selectedCustomers.value = selection;
};

// 批量删除
const handleBatchDelete = () => {
  if (selectedCustomers.value.length === 0) {
    ElMessage.warning('请至少选择一条记录');
    return;
  }
  
  ElMessageBox.confirm(`确认要删除选中的 ${selectedCustomers.value.length} 条记录吗？`, '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(async () => {
    try {
      // 创建删除操作的Promise数组
      const deletePromises = selectedCustomers.value.map(item => deleteCustomer(item.id));
      
      // 并行执行所有删除操作
      await Promise.all(deletePromises);
      
      ElMessage.success('批量删除成功');
      getList();
    } catch (error) {
      console.error(error);
      ElMessage.error('批量删除失败');
    }
  }).catch(() => {});
};

// 处理导入
const handleImport = () => {
  if (uploadRef.value) {
    uploadRef.value.clearFiles();
  }
  importFile.value = null;
  importDialogVisible.value = true;
};

// 处理文件变化
const handleFileChange = (file) => {
  if (!file) {
    importFile.value = null;
    return false;
  }
  
  // 检查是否是Excel文件
  const isExcel = /\.(xlsx|xls)$/.test(file.name.toLowerCase());
  if (!isExcel) {
    ElMessage.error('只能上传Excel文件(.xlsx, .xls)');
    if (uploadRef.value) {
      uploadRef.value.clearFiles();
    }
    return false;
  }
  
  // 保存文件引用
  importFile.value = file.raw;
  ElMessage.success(`文件"${file.name}"准备就绪，请点击"开始导入"按钮开始导入`);
  return true;
};

// 处理文件拖拽
const handleDrop = (file) => {
  console.log('文件已拖拽到上传区域', file);
  ElMessage.success('文件已上传，请点击"开始导入"按钮');
};

// 处理超出文件数量限制
const handleExceed = () => {
  ElMessage.warning('只能上传1个文件，请先删除已选择的文件');
};

// 提交导入
const submitImport = async () => {
  if (!importFile.value) {
    ElMessage.warning('请先选择或拖拽文件');
    return;
  }
  
  // 创建导入进度对话框
  ElMessageBox.confirm(
    `<div class="import-progress-container">
      <p class="progress-title">正在导入数据，请耐心等待...</p>
      <div class="progress-info">
        <span>导入进度:</span>
        <el-progress :percentage="0" />
      </div>
      <p class="progress-status">准备中...</p>
    </div>`,
    '导入进度',
    {
      dangerouslyUseHTMLString: true,
      showCancelButton: true,
      showConfirmButton: false,
      cancelButtonText: '取消导入',
      distinguishCancelAndClose: true,
      customClass: 'import-progress-dialog',
      beforeClose: (action, instance, done) => {
        if (action === 'cancel') {
          ElMessageBox.confirm('确定要取消导入吗？', '提示', {
            type: 'warning'
          }).then(() => {
            // 用户确认取消
            importLoading.value = false;
            done();
          }).catch(() => {
            // 用户取消操作，继续导入
          });
          return;
        }
        done();
      }
    }
  ).catch(action => {
    // 处理关闭操作
    if (action === 'cancel') {
      importLoading.value = false;
      return Promise.reject('取消导入');
    }
  });
  
  const formData = new FormData();
  formData.append('file', importFile.value);
  
  try {
    importLoading.value = true;
    
    // 执行导入请求
    const response = await importCustomers(formData);
    
    if (response.success) {
      // 更新进度条到100%
      updateProgressUI(100, response.imported_count, response.total_rows, '导入完成!');
      
      // 关闭进度对话框
      setTimeout(() => {
        ElMessageBox.close();
        
        // 构建成功消息
        let successMessage = `导入成功，共导入 ${response.imported_count} 条记录`;
        
        // 如果有跳过的记录，添加跳过信息
        if (response.skipped_count && response.skipped_count > 0) {
          successMessage += `，跳过 ${response.skipped_count} 条已存在的记录`;
        }
        
        // 如果有错误记录，添加错误信息
        if (response.errors && response.errors.length > 0) {
          successMessage += `，${response.errors.length} 条记录导入失败`;
        }
        
        // 基本消息通知
      ElMessage.success({
          message: successMessage,
        duration: 5000
      });
        
        // 处理详情显示逻辑
        let needShowDetails = false;
        
        // 如果跳过的客户较多，使用弹窗显示详情
        if (response.skipped_names && response.skipped_names.length > 5) {
          needShowDetails = true;
        }
        
        // 如果有错误记录，也显示详情
        if (response.errors && response.errors.length > 0) {
          needShowDetails = true;
        }
        
        // 如果需要显示详情，创建详情弹窗
        if (needShowDetails) {
          let detailsHtml = '<div style="max-height: 500px; overflow-y: auto;">';
          
          // 添加跳过客户详情
          if (response.skipped_names && response.skipped_names.length > 0) {
            detailsHtml += `
              <div class="details-section">
                <h4>已存在的客户 (${response.skipped_names.length})</h4>
                <ul style="padding-left: 20px; margin-top: 10px;">
                  ${response.skipped_names.slice(0, 100).map(name => `<li>${name}</li>`).join('')}
                  ${response.skipped_names.length > 100 ? `<li>...还有 ${response.skipped_names.length - 100} 条记录未显示</li>` : ''}
                </ul>
              </div>
            `;
          }
          
          // 添加错误记录详情
          if (response.errors && response.errors.length > 0) {
            detailsHtml += `
              <div class="details-section">
                <h4>导入失败的记录 (${response.errors.length})</h4>
                <ul style="padding-left: 20px; margin-top: 10px; color: #F56C6C;">
                  ${response.errors.map(error => `<li>${error}</li>`).join('')}
                </ul>
              </div>
            `;
          }
          
          detailsHtml += '</div>';
          
          // 显示详情弹窗
          ElMessageBox.alert(
            detailsHtml,
            '导入详情',
            {
              dangerouslyUseHTMLString: true,
              confirmButtonText: '确定',
              callback: () => {
                // 关闭弹窗后刷新数据
      getList();
              }
            }
          );
    } else {
          // 如果没有需要显示的详情，直接刷新列表
          getList();
        }
        
        importDialogVisible.value = false;
      }, 1000);
    } else {
      // 处理导入失败
      ElMessageBox.close();
      ElMessage.error({
        message: response.message || '导入失败',
        duration: 5000
      });
    }
  } catch (error) {
    // 显示详细错误
    console.error('导入失败:', error);
    
    // 关闭进度对话框
    ElMessageBox.close();
    
    // 显示错误信息
    let errorMessage = '导入失败';
    let errorDetails = '';
    
    if (error.response && error.response.data) {
      if (error.response.data.message) {
        errorMessage = error.response.data.message;
      }
      
      if (error.response.data.details) {
        errorDetails = error.response.data.details;
      }
    } else if (error.message) {
      errorMessage = error.message;
    }
    
    ElMessageBox.alert(
      `<div style="max-height: 300px; overflow-y: auto;">
        <p>导入失败，原因：${errorMessage}</p>
        ${errorDetails ? `<p>详细信息：</p>
        <pre style="background: #f5f5f5; padding: 10px; overflow: auto; max-height: 200px;">${errorDetails}</pre>` : ''}
      </div>`,
      '导入错误',
      {
        dangerouslyUseHTMLString: true,
        confirmButtonText: '确定',
        type: 'error'
      }
    );
  } finally {
    importLoading.value = false;
  }
};

// 更新进度条UI
const updateProgressUI = (percentage, processed, total, statusText) => {
  const progressBar = document.querySelector('.import-progress-container .el-progress');
  const statusElement = document.querySelector('.import-progress-container .progress-status');
  
  if (progressBar) {
    const progressBarInstance = progressBar.__vue__;
    if (progressBarInstance) {
      progressBarInstance.percentage = percentage;
    }
  }
  
  if (statusElement) {
    statusElement.textContent = statusText || `正在处理... (${processed}/${total})`;
  }
};

// 下载导入模板
const downloadTemplate = async () => {
  try {
    const response = await getImportTemplate();
    const blob = new Blob([response.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
    const link = document.createElement('a');
    link.href = URL.createObjectURL(blob);
    link.download = '客户导入模板.xlsx';
    link.click();
    URL.revokeObjectURL(link.href);
  } catch (error) {
    console.error('下载模板失败:', error);
    ElMessage.error('下载模板失败');
  }
};
</script>

<style scoped>
.app-container {
  padding: 20px;
}

.app-card {
  border-radius: 16px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  background-color: #fff;
  border: none;
  overflow: hidden;
  transition: all 0.3s ease;
  margin-bottom: 20px;
}

.search-bar {
  display: flex;
  align-items: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.search-input {
  width: 280px;
  border-radius: 8px;
}

.search-button, .reset-button {
  border-radius: 8px;
  height: 40px;
  font-weight: 500;
  transition: all 0.3s ease;
}

.search-button {
  background-color: #0071e3;
  border-color: #0071e3;
}

.search-button:hover {
  background-color: #0077ed;
  border-color: #0077ed;
  transform: translateY(-1px);
}

.reset-button {
  color: #606266;
  background-color: #f5f7fa;
  border-color: #f5f7fa;
}

.reset-button:hover {
  background-color: #e4e7ed;
  border-color: #e4e7ed;
}

.table-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 20px;
  width: 100%;
}

.left-buttons {
  display: flex;
  gap: 10px;
}

.right-buttons {
  display: flex;
  gap: 10px;
}

.action-button {
  border-radius: 8px;
  padding: 10px 16px;
  height: 40px;
  font-weight: 500;
  display: flex;
  align-items: center;
  transition: all 0.3s ease;
  flex-shrink: 0;
}

.add-button {
  background-color: #0071e3;
  border-color: #0071e3;
}

.export-button {
  background-color: #67c23a;
  border-color: #67c23a;
}

.import-button {
  background-color: #0071e3;
  border-color: #0071e3;
}

.action-button:hover {
  transform: translateY(-1px);
}

.button-icon {
  margin-right: 6px;
}

.data-table {
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #ebeef5;
}

:deep(.el-table th) {
  background-color: #f5f7fa;
  color: #606266;
  font-weight: 600;
  padding: 12px 0;
}

:deep(.el-table td) {
  padding: 12px 0;
}

:deep(.el-table--border) {
  border-radius: 8px;
  overflow: hidden;
}

.table-button {
  font-size: 14px;
  font-weight: 500;
}

.source-tag {
  border-radius: 20px;
  padding: 2px 10px;
  font-size: 12px;
}

.table-pagination {
  margin-top: 24px;
  display: flex;
  justify-content: flex-end;
}

.pagination {
  --el-pagination-button-bg-color: #f5f7fa;
  --el-pagination-hover-color: #0071e3;
}

:deep(.el-pagination.is-background .el-pager li:not(.is-disabled).is-active) {
  background-color: #0071e3;
}

.order-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.order-link {
  font-size: 13px;
  color: #0071e3;
}

.no-data {
  color: #909399;
  font-size: 13px;
  font-style: italic;
}

.custom-dialog {
  border-radius: 16px;
  overflow: hidden;
}

:deep(.el-dialog__header) {
  padding: 20px 24px;
  border-bottom: 1px solid #f0f0f0;
  margin-right: 0;
}

:deep(.el-dialog__body) {
  padding: 24px;
}

:deep(.el-dialog__footer) {
  padding: 16px 24px;
  border-top: 1px solid #f0f0f0;
}

.dialog-form {
  padding: 0 12px;
}

.form-input {
  width: 100%;
  border-radius: 8px;
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.cancel-button, .submit-button {
  border-radius: 8px;
  padding: 10px 20px;
  font-weight: 500;
}

.submit-button {
  background-color: #0071e3;
  border-color: #0071e3;
}

.submit-button:hover {
  background-color: #0077ed;
  border-color: #0077ed;
}

.order-detail {
  padding: 16px;
  border-radius: 8px;
  background-color: #f8f9fa;
}

:deep(.el-descriptions__label) {
  font-weight: 600;
}

.import-container {
  padding: 0 12px;
}

.import-tips {
  margin-bottom: 20px;
  padding: 16px;
  background-color: #f8f9fa;
  border-radius: 8px;
  font-size: 14px;
}

.import-tips p {
  font-weight: 600;
  margin-bottom: 8px;
  color: #303133;
}

.import-tips ol {
  padding-left: 20px;
  margin: 0;
  color: #606266;
}

.template-download {
  margin-bottom: 20px;
}

.download-button {
  display: flex;
  align-items: center;
  font-size: 14px;
  color: #0071e3;
}

.download-button:hover {
  color: #0077ed;
}

.upload-demo {
  margin-bottom: 20px;
}

:deep(.el-upload--text) {
  width: 100%;
}

:deep(.el-upload-dragger) {
  width: 100%;
  height: 180px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-radius: 8px;
  border: 2px dashed #dcdfe6;
}

:deep(.el-upload-dragger:hover) {
  border-color: #0071e3;
}

:deep(.el-icon--upload) {
  font-size: 48px;
  color: #0071e3;
  margin-bottom: 10px;
}

:deep(.el-upload__text) {
  font-size: 16px;
  color: #606266;
}

:deep(.el-upload__text em) {
  color: #0071e3;
  font-style: normal;
  cursor: pointer;
}

:deep(.el-upload__tip) {
  font-size: 13px;
  color: #909399;
  line-height: 1.5;
}
</style>

<!-- 添加全局样式 -->
<style>
/* 进度条对话框样式 */
.import-progress-dialog {
  width: 450px !important;
}

.import-progress-dialog .el-message-box__content {
  padding: 20px !important;
}

.import-progress-dialog .el-message-box__message {
  padding: 0 !important;
}

.import-progress-container {
  padding: 10px;
}

.import-progress-container .progress-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 20px;
  color: #303133;
}

.import-progress-container .progress-info {
  margin-bottom: 15px;
}

.import-progress-container .el-progress {
  margin-top: 10px;
  margin-bottom: 15px;
}

.import-progress-container .progress-status {
  font-size: 14px;
  color: #606266;
  margin-top: 10px;
}

/* 导入详情样式 */
.details-section {
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 1px solid #eaeaea;
}

.details-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.details-section h4 {
  margin: 0 0 10px 0;
  color: #303133;
  font-size: 16px;
  font-weight: 600;
}

.details-section ul {
  margin: 0;
  max-height: 250px;
  overflow-y: auto;
  border-radius: 4px;
  background-color: #f9f9f9;
  padding: 10px 10px 10px 30px;
}

.details-section ul li {
  margin-bottom: 5px;
  padding: 3px 0;
  font-size: 14px;
}

/* 错误消息样式 */
.error-details {
  max-height: 200px;
  overflow-y: auto;
  background-color: #f8f8f8;
  border-radius: 4px;
  padding: 12px;
  margin-top: 10px;
  font-family: monospace;
  font-size: 12px;
  color: #e6a23c;
  white-space: pre-wrap;
}
</style> 